#include "DataConfig.h"
#include "DataConfigMgr.h"

CRoleConfigMgr::CRoleConfigMgr()
{

}
CRoleConfigMgr::~CRoleConfigMgr()
{

}


void CRoleConfigMgr::prase(rapidjson::Value& valueDt)
{
	CRoleData* roleDt = new CRoleData();
	roleDt->nId = valueDt["id"].GetInt();
	roleDt->nHp = valueDt["hp"].GetInt();
	roleDt->nShield = valueDt["shield"].GetInt();
	roleDt->nMp = valueDt["mp"].GetInt();
	roleDt->nSpeed = valueDt["speed"].GetInt();
	roleDt->strName = valueDt["name"].GetString();
	roleDt->strDiedImg = valueDt["diedImg"].GetString();
	rapidjson::Value& idleImg = valueDt["idleImg"];
	for (int i = 0; i < idleImg.Size(); i++){
		roleDt->vecIdleImg.push_back(idleImg[i].GetString());
	}
	rapidjson::Value& moveImg = valueDt["moveImg"];
	for (int i = 0; i < moveImg.Size(); i++){
		roleDt->vecMoveImg.push_back(moveImg[i].GetString());
	}
	m_vecData.push_back(roleDt);
}



CMonsterConfigMgr::CMonsterConfigMgr()
{

}
CMonsterConfigMgr::~CMonsterConfigMgr()
{

}


void CMonsterConfigMgr::prase(rapidjson::Value& valueDt)
{
	CMonsterData* monsterDt = new CMonsterData();
	monsterDt->nId = valueDt["id"].GetInt();
	monsterDt->nHp = valueDt["hp"].GetInt();
	monsterDt->nSpeed = valueDt["speed"].GetInt();
	monsterDt->nAiInterval = valueDt["aiInterval"].GetInt();
	monsterDt->strName = valueDt["name"].GetString();
	monsterDt->strSort = valueDt["sort"].GetString();
	monsterDt->strDiedImg = valueDt["diedImg"].GetString();
	rapidjson::Value& idleImg = valueDt["idleImg"];
	for (int i = 0; i < idleImg.Size(); i++){
		monsterDt->vecIdleImg.push_back(idleImg[i].GetString());
	}
	rapidjson::Value& moveImg = valueDt["moveImg"];
	for (int i = 0; i < moveImg.Size(); i++){
		monsterDt->vecMoveImg.push_back(moveImg[i].GetString());
	}
	rapidjson::Value& injuredImg = valueDt["injuredImg"];
	for (int i = 0; i < injuredImg.Size(); i++){
		monsterDt->vecInjuredImg.push_back(injuredImg[i].GetString());
	}
	m_vecData.push_back(monsterDt);
}


CBulletConfigMgr::CBulletConfigMgr()
{

}

CBulletConfigMgr::~CBulletConfigMgr()
{

}

void CBulletConfigMgr::prase(rapidjson::Value& valueDt)
{
	CBulletData* bullet = new CBulletData();
	bullet->nId = valueDt["id"].GetInt();
	bullet->nAtk= valueDt["atk"].GetInt();
	bullet->fDestoryTime = valueDt["destoryTime"].GetFloat();
	bullet->nSpeed = valueDt["speed"].GetInt();

	rapidjson::Value& idleImg = valueDt["idleImg"];
	for (int i = 0; i < idleImg.Size(); i++){
		bullet->vecIdleImg.push_back(idleImg[i].GetString());
	}
	rapidjson::Value& destoryImg = valueDt["destoryImg"];
	for (int i = 0; i < destoryImg.Size(); i++){
		bullet->vecDestoryImg.push_back(destoryImg[i].GetString());
	}
	m_vecData.push_back(bullet);
}



CWeaponConfigMgr::CWeaponConfigMgr()
{
}

CWeaponConfigMgr::~CWeaponConfigMgr()
{
}

void CWeaponConfigMgr::prase(rapidjson::Value& valueDt)
{
	CWeaponData* weaponData = new CWeaponData();
	weaponData->nId = valueDt["id"].GetInt();
	weaponData->nBulletId = valueDt["bulletId"].GetInt();
	weaponData->strPicName = valueDt["picName"].GetString();
	m_vecData.push_back(weaponData);
}





void CLoader::loadConfig()
{
	CRoleConfigMgr* pCRoleConfigMgr = new CRoleConfigMgr();
	pCRoleConfigMgr->loadFile("config/roleDt.json");
	CDataConfigMgr::getInstance()->addConfigMgr("RoleConfigMgr", pCRoleConfigMgr);

	CMonsterConfigMgr* pMonsterConfigMgr = new CMonsterConfigMgr();
	pMonsterConfigMgr->loadFile("config/monsterDt.json");
	CDataConfigMgr::getInstance()->addConfigMgr("MonsterConfigMgr", pMonsterConfigMgr);

	CBulletConfigMgr* pBulletConfigMgr = new CBulletConfigMgr();
	pBulletConfigMgr->loadFile("config/bulletDt.json");
	CDataConfigMgr::getInstance()->addConfigMgr("BulletConfigMgr", pBulletConfigMgr);

	CWeaponConfigMgr* pWeaponConfigMgr = new CWeaponConfigMgr();
	pWeaponConfigMgr->loadFile("config/weaponDt.json");
	CDataConfigMgr::getInstance()->addConfigMgr("WeaponConfigMgr", pWeaponConfigMgr);
}


